package com.scd.encrypt.utils;


import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jsoup.Connection;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;


public class HttpUtils {
	
	public static String sendPostByjsoup(String url,String param, String cookie) throws IOException{
		Connection con = Jsoup.connect(url).ignoreContentType(true);
		con.header("Accept", "*/*");
		con.header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36");
		con.header("Cookie", cookie);
//		String start_day = "2018-11-01 00:00:00";
//		String toend_day = "2018-11-29 00:00:00";
//		String staff_w3_id = "sWX615626";
//		String queryStatus = "1";
//		con.data("start_day", start_day);
//		con.data("toend_day", toend_day);
//		con.data("staff_w3_id", staff_w3_id);
//		con.data(param);
		Response rs = con.execute();
		return rs.body();
	}
	
	public static String doPost(String url, String param){
		CloseableHttpClient httpclient = HttpClientBuilder.create().build();
		HttpPost post = new HttpPost(url);
		String result = "";
		try {
			StringEntity s = new StringEntity(param);
			s.setContentEncoding("UTF-8");
			//发送json数据需要设置contentType
			s.setContentType("application/json");
			post.setEntity(s);
			HttpResponse res = httpclient.execute(post);
			if(res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
				result = EntityUtils.toString(res.getEntity());
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return result;
	}

	public static void main(String[] args)  {
	}

}
